/**
 * @Description:
 * @Author: CHEHSHUANG
 * @Date: 2019/3/14
 */
import React, {Component} from 'react';
import {Checkbox, Form, Input, Radio} from "antd";
import StandardModal from "../../../commons/components/StandardModal";
const FormItem = Form.Item;
class AddOrEditAccountModal extends Component {
  componentDidMount(){
    this.props.onRef&&this.props.onRef(this);
  }
  getFormValue = () => {
    let result = false;
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        result = values;
        const {editData} = this.props;
        if (editData) {
          result.id = editData.id || null;
        }
      }
    });
    return result;
  }
  render() {
    const formItemLayout = {
      labelCol: {
        span: 8
      },
      wrapperCol: {
        span: 12
      },
    };

    const {parentData,confirmLoading, visible, onCancel, onOk, editData, flag} = this.props;
    const {getFieldDecorator} = this.props.form;
    let initValue = editData;
    let title = "编辑账号";
    if (flag === "add") {
      title = "新增账号";
      initValue = {}
    }
    return (
      <StandardModal
        title={title}
        visible={visible}
        onOk={onOk}
        onCancel={onCancel}
        width={600}
        confirmLoading={confirmLoading}
        maskClosable={false}
      >
        <Form>
          <FormItem
            {...formItemLayout}
            label="昵称">
            {getFieldDecorator('nickName', {
              initialValue: initValue&&initValue.nickName ? initValue.nickName : "",
              rules: [{required: true, message: '请填写名称!'}]
            })(
              <Input/>
            )}
          </FormItem>
          <FormItem
            {...formItemLayout}
            label="账号">
            {getFieldDecorator('account', {
              initialValue: initValue&&initValue.account ? initValue.account : "",
              rules: [{required: true, message: '请填写账号!'}]
            })(
              <Input />
            )}
          </FormItem>
        </Form>
      </StandardModal>
    );
  }
}

export default Form.create()(AddOrEditAccountModal);
